function varargout = Progress_Detail(varargin)
% PROGRESS_DETAIL M-file for Progress_Detail.fig
%      PROGRESS_DETAIL, by itself, creates a new PROGRESS_DETAIL or raises the existing
%      singleton*.
%
%      H = PROGRESS_DETAIL returns the handle to a new PROGRESS_DETAIL or the handle to
%      the existing singleton*.
%
%      PROGRESS_DETAIL('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in PROGRESS_DETAIL.M with the given input arguments.
%
%      PROGRESS_DETAIL('Property','Value',...) creates a new PROGRESS_DETAIL or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Progress_Detail_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Progress_Detail_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Progress_Detail

% Last Modified by GUIDE v2.5 20-Feb-2008 14:17:25

% Begin initialization code - DO NOT EDIT
gui_Singleton = 0;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Progress_Detail_OpeningFcn, ...
                   'gui_OutputFcn',  @Progress_Detail_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before Progress_Detail is made visible.
function Progress_Detail_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to Progress_Detail (see VARARGIN)

% Choose default command line output for Progress_Detail
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Progress_Detail wait for user response (see UIRESUME)
% uiwait(handles.progress_detail);


% --- Outputs from this function are returned to the command line.
function varargout = Progress_Detail_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on selection change in progress_list_models.
function progress_list_models_Callback(hObject, eventdata, handles)
if isempty(handles);handles=guihandles(hObject);end
Progress_Detail_FillGUI(handles.progress_detail);
%disp(':-)')

% hObject    handle to progress_list_models (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns progress_list_models contents as cell array
%        contents{get(hObject,'Value')} returns selected item from progress_list_models


% --- Executes during object creation, after setting all properties.
function progress_list_models_CreateFcn(hObject, eventdata, handles)
% hObject    handle to progress_list_models (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end




% --------------------------------------------------------------------
function Export_Callback(hObject, eventdata, handles)
% hObject    handle to Export (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function save_as_Callback(hObject, eventdata, handles)
[filename, pathname, filterindex]=uiputfile({'*.pdf','Portable Document Format (*.pdf)';'*.fig','Figures (*.fig)'},'Save as');
%disp(':-)')
switch filterindex
    case 1 % pdf
        set(gcf,'PaperPositionMode','auto');
        print('-dpdf',[pathname,filename]);
    case 2 % matlab fig
        hgsave([pathname,filename]);    
end

% hObject    handle to save_as (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)




% --------------------------------------------------------------------
function copy_to_clipboard_Callback(hObject, eventdata, handles)
hgexport(gcf,'-clipboard')
% hObject    handle to copy_to_clipboard (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)




% --------------------------------------------------------------------
function help_Callback(hObject, eventdata, handles)
web('http://bioinformaticstation.org')
% hObject    handle to help (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)




% --- Executes on button press in cluster_analysis.
function cluster_analysis_Callback(hObject, eventdata, handles)
NRN_training_cluster_analysis;
% hObject    handle to cluster_analysis (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)




% --------------------------------------------------------------------
function sensitivity_Callback(hObject, eventdata, handles)
% hObject    handle to sensitivity (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
h_fig=get(get(hObject,'Parent'),'Parent');
h=guihandles(h_fig);
dt=get(h.select_model,'UserData');
[lala,m]=min(mean(dt.predict.dy)); %optimal number of variables

% Look for sensitivity analysis information in the pie chard handle
S=get(h.member_pie,'UserData');
S.s=100*S.s./sum(S.s); %normalize to addup to 100%
[filename,directory]=uiputfile('*.*','Name Excel file for output');
fid=fopen([directory,filename,'.xls'],'w');
% Export Variable sensitivity
fprintf(fid,'%s\t%s\n','Parameter','Relative Importance');
for i=1:length(S.s)
    fprintf(fid,'%s\t%.1f\n',S.vars{i},S.s(i));
end
%Export Committee composition
GC=get(h.var_addition,'Children');
mj=get(GC(1),'YData'); % <-- error that would be obtained by using majority outcome
var_add_w=[mj(1),get(GC(3),'YData')]; % rofile of % of wrong neighbors
%fprintf(fid,'\n%s\n','Committee Composition:');
fprintf(fid,'\n%s\t%s\n','%Wrong Closest Neighbors','Committee Composition');
fprintf(fid,'%.1f',var_add_w(1))
for i=1:size(dt.predict.var,1)
    fprintf(fid,'\t%s',['cmte#',num2str(i)]);
end
for i=1:m
    fprintf(fid,'\n%.1f',var_add_w(i+1));
    fprintf(fid,'\t%s',dt.vars{dt.predict.var(:,i)});
end
fclose(fid);pause(0.1);
system(['explorer ',directory,filename,'.xls']);

%Paste to clipboard
%cb='';
%cb=[cb,sprintf('%s\t%s\n','Parameter','Relative Importance')];
%for i=1:length(S.s)
%    cb=[cb,sprintf('%s\t%.1f\n',S.vars{i},S.s(i))];
%end
%clipboard('copy',cb);


